<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>相关资讯</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
	#parentDiv{
			width:1000px;
			height:785px;
			background-color:#fff;
			margin-left:250px;
			margin-top:8px;
		}
		#oneSpan{
			font-size: 18px;
			padding:10px 10px 0px;
			margin-left:25px;
			margin-bottom:15px;
		}
		#twoSpan{
			font-size: 18px;
			padding:10px 10px 0px;
			margin-left:25px;
		}
		#title{
			width:910px;
			height:50px;
			background-color:#eee;
			margin-left:25px;
			border:1px solid #eee;
		}
		#content{
			width:910px;
			height:200px;
			background-color:#eee;
			margin-left:25px;
			border:1px solid #eee;
		}
		#btn{
			width:100px;
			height:30px;
			float:right;
			margin-right:70px;
			margin-top:20px;
		}
		#ret{
			font-size: 18px;
			margin-left:30px;
		}
	</style>
	<script type="text/javascript" src="/EasyBuy/statics/js/jquery-1.8.2.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#title").blur(function (){				
				if($("#title").val()==null || $("#title").val()==""){
					$("#titlediv").css("font-size","18px");	
					$("#titlediv").css("color","red");
					$("#titlediv").css("margin-left","30px");
					$("#titlediv").text("标题不能为空");
				}else if($("#title").val()!=null || $("#title").val()!=""){
					$("#titlediv").text("");
				}
			});
			
			$("#content").blur(function (){
				 if($("#content").val()==null || $("#content").val()==""){
				 	$("#contentdiv").css("font-size","18px");	
					$("#contentdiv").css("color","red");
					$("#contentdiv").css("margin-left","30px");
					$("#contentdiv").text("内容不能为空");		
				}else  if($("#content").val()!=null || $("#content").val()!=""){
					$("#contentdiv").text("");
				}
			});
			
			$("#btn").click(function(){
				if($("#btn").val()=="确认添加"){
					location.href="ConsultationServlet?opr=insert&title="+$("#title").val()+"&content="+$("#content").val();		
				}else if($("#btn").val()=="确认修改"){
					$.get("ConsultationServlet","opr=update&id="+$("#id").val()+"&title="+$("#title").val()+"&content="+$("#content").val(),call);
					function call(data){
						if(data=="cg"){
							alert("修改成功");
							location.href="/EasyBuy/backend/news/Member_Member.jsp";
						}else  if(data=="sb"){
							alert("修改失败");
							location.href="/EasyBuy/backend/news/Member_Member.jsp";
						}
					}
				}
			});
		
		});
	</script>
  </head>
  <body>

  	<c:choose>
	  	<c:when test="${empty applicationScope.id}">
	  		<% response.sendRedirect("/EasyBuy/pre/Login.jsp");%>
	  	</c:when>
	  	<c:otherwise>
	  		<%@ include file="../../common/header.jsp" %>
			<%@ include file="../../common/backendHeader.jsp" %>
			 <c:choose>
				<c:when test="${empty applicationScope.type }">
					<% 	request.getRequestDispatcher("../../UserServlet?opr=type&href=Member_Address&href1=order").forward(request, response); %>
				</c:when>
				<c:otherwise>
					<c:if test="${applicationScope.type==1 }">
		  				<%@ include file="../../common/sideMamber.jsp" %> 
					</c:if>
					<c:if test="${applicationScope.type==0 }">
						<%@ include file="../../common/sideUser.jsp" %> 
					</c:if>
				</c:otherwise>
			 </c:choose>
	  	</c:otherwise>
  	</c:choose>
    
 	
  <div id="parentDiv">
  	<div id="oneSpan">标题</div>
  	<c:if test="${empty list }">
  		<div>
	  		<input type="text" name="title" id="title" ><div id="titlediv"></div>
	  	</div>
	  	<div id="twoSpan">内容</div>
	  	<div>
	  		<textarea  name="content" id="content"></textarea><div id="contentdiv"></div>
	  	</div>
  		<div>
	  		<input type="button" value="确认添加" id="btn">
	  	</div>
  	</c:if>
  	<c:if test="${!empty list }">
	  	<c:forEach var="list" items="${list }">
	  		<div>
	  			<input value="${list.id }" id="id" style="display:none"> 
		  		<input type="text" name="title" id="title" value="${list.title }"><div id="titlediv"></div>
		  	</div>
		  	<div id="twoSpan">内容</div>
		  	<div>
		  		<textarea  name="content" id="content">${list.content }</textarea><div id="contentdiv"></div>
		  	</div>
	 		<c:if test="${type==0 }">    
	 			<div>
		  			<input type="button" value="确认添加" id="btn" disabled>
		  		</div>
	 		</c:if>
	 		<c:if test="${type==1 }">
	 			<div>
		  			<input type="button" value="确认修改" id="btn">
		  		</div>
	 		</c:if>
	  	</c:forEach>
  	</c:if>
  	<p id="ret"><a href="/EasyBuy/backend/news/Member_Member.jsp">返回列表</a></p>
  </div>
  <%@ include file="../../common/footer.jsp" %>
  </body>
</html>
